﻿using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using DnD.ViewModels;
using DnD.Model;
using System.Diagnostics;

namespace DnD
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = new CardListViewModel(this);
        }

        // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            NavigationService.RemoveBackEntry();
            NavigationService.RemoveBackEntry();
            NavigationService.RemoveBackEntry();
            //if (!App.ViewModel.IsDataLoaded)
            //{
            //    App.ViewModel.LoadData();
            //}
        }

        private void CardList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((CardListViewModel)DataContext).SelectedCard = ((LongListSelector)sender).SelectedItem as Card;
            //NavigationService.Navigate(new Uri("/CardPage.xaml", UriKind.Relative));
        }

        private void AppBar_Click(object sender, EventArgs e)
        {
            ((CardListViewModel)DataContext).handleMenuRequest(((ApplicationBarIconButton)sender).Text);
        }

        

       
        
    }
}